#pragma once

#include <iosfwd>
#include <vector>
#include <sstream>


namespace cpputil
{//noncopyable
	class noncopyable
	{
	protected:
		noncopyable() {}
		~noncopyable() {}
	private:  // emphasize the following members are private
		noncopyable( const noncopyable& );
		const noncopyable& operator=( const noncopyable& );
	};

	//auto ptr set function : delete ptr object, set ptr to 0/new ptr
	template<class T>
	void autoPtrReset(T*& p, T* newp=0)
	{
		if(p)
			delete p;
		p = newp;
	}


	template<class T>
	void deleteMapItem(T& map)
	{
		for(T::iterator itr = map.begin();itr!=map.end();++itr)
		{
			delete itr->second;
		}
		map.clear();
	}

	template<class T>
	void deleteVectorItem(T& vec)
	{
		for(T::iterator itr = vec.begin();itr!=vec.end();++itr)
		{
			delete *itr;
		}
		vec.clear();
	}

	typedef std::basic_stringstream<TCHAR, std::char_traits<TCHAR>,std::allocator<TCHAR> > tstringstream;
	
	template<class T>
	bool strConvert(const TCHAR* s, T& val)
	{
		tstringstream str(s);	
		str >> val;
		return !str.fail() && str.eof();
	}

	template<class T>
	bool toString(TCHAR* s, const T& val){
		tstringstream str(s);
		str<<val;
		return !str.fail() && str.eof();
	}

}



